  import {axios} from "../../utils/request"
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  login(){
    return new Promise((resolve,reject)=>{
      wx.login({
        success(res){
          resolve(res)
        },
        fail(err){
          reject(err)
        }
     })
    })
  },
  async toLogin(){
    const getInfo = ()=> wx.getUserProfile({desc:"用于用户注册"})
    const [info,loginData] =  await Promise.all([getInfo(),this.login()])
    let UserData = {code:(loginData as any).code,...info.userInfo}
    let res =  await axios("/user/login","POST",{...UserData}) as any
    if(res.statusCode==200||res.data.statusCode==200){
      wx.setStorageSync('token',res.data.data.token)
      wx.setStorageSync('userInfo',info.userInfo)
      wx.setStorageSync('isLogin',true)
      this.setData({
        userInfo:info.userInfo
      })
    }
    wx.navigateBack()
  }
})